<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-form-item label="店铺名称" prop="shopname">
          <el-input v-model="filters.shopname" placeholder="店铺名称"></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="ordernumber">
          <el-input v-model="filters.ordernumber" placeholder="订单号"></el-input>
        </el-form-item>
        <el-form-item label="商品名称" prop="productname">
          <el-input v-model="filters.productname" placeholder="商品名称"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" prop="startTime">
          <el-date-picker
            v-model="filters.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始时间" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-form-item prop="endTime">
          <el-date-picker
            v-model="filters.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束时间" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否展示" prop="exhibition">
          <el-select v-model="filters.exhibition" placeholder="是否展示">
            <el-option label="全选" value></el-option>
            <el-option
              v-for="item in exhibitionOption"
              :key="item.status"
              :label="item.label"
              :value="item.status">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      :showEditOperation="false"
      :showBatchDelete="true"
      :showDeleteOperation="false"
      :showDetailOperation="true"
      @findPage="findPage"
      @handleDetail="handleDetail"
      ref="CyTable"
    ></cy-table>
    <!--新增编辑界面-->
    <el-dialog title="详情" width="60%" :visible.sync="editDialogVisible" :close-on-click-modal="false">
      <el-form
        :model="dataForm"
        :inline="true"
        label-width="80px"
        ref="dataForm"
        :size="size"
        label-position="right"
      >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>

        <div class="block">
          <span class="demonstration">商品图片</span>
          <el-carousel height="400px" type="card">
            <el-carousel-item v-for="item in productPics" :key="item" autoplay="true" interval="3000">
              <h3 class="small"><el-image :src="item" fit="fill"></el-image></h3>
            </el-carousel-item>
          </el-carousel>
        </div>

        <el-form-item label="是否展示" prop="exhibition">
          <el-input v-model="dataForm.exhibition" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="商品名称" prop="productname">
          <el-input v-model="dataForm.productname" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="发表人" prop="createuser">
          <el-input v-model="dataForm.createuser" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="发表时间" prop="create_time">
          <el-input v-model="dataForm.create_time" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="发表内容" prop="content">
          <el-input v-model="dataForm.content" :disabled="true" type="textarea" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="回复内容" prop="replycontent">
          <el-input v-model="dataForm.replycontent" type="textarea" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm"
          :loading="editLoading"
        >{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        shopname: "",
        ordernumber: "",
        productname: "",
        startTime: "",
        endTime: "",
        exhibition: "",
        t: "evaluationManagement",
        queryname: ""
      },
      exhibitionOption: [{
          status: '是',
          label: '是'
      }, {
          status: '否',
          label: '否'
      }],
      options: {},
      columns: [
        { prop: "id", label: "ID", minWidth: 50 },
        { prop: "productname", label: "商品名称", minWidth: 120 },
        { prop: "ordernumber", label: "订单号", minWidth: 100 },
        { prop: "createuser", label: "发表人", minWidth: 100 },
        { prop: "productscore", label: "商品评分", minWidth: 100 },
        { prop: "content", label: "评价内容", minWidth: 100 },
        { prop: "sunsheet", label: "晒单", minWidth: 100 },
        { prop: "exhibition", label: "展示", minWidth: 100 },
        { prop: "shopname", label: "店铺名称", minWidth: 100 },
        { prop: "create_time", label: "发表时间", minWidth: 100 }
      ],
	  filterColumns:[],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
      // 新增编辑界面数据
      dataForm: {},
      productPics: {}
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) {
      this.$refs.CyTable.findPage(this.filters);
    },
    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    //详情
    handleDetail(data) {
        let this_ = this;
        this.editDialogVisible = true;
        let param = {};
        param.t = "evaluationManagement";
        param.id = data.row.id;
        this.utils.request.queryUserInfo(param, function(data) {
            if (data.data != null) {
                this_.dataForm = data.data;
              var bigpicstr = data.data.bigpic;
              var arr = new Array();
              if(bigpicstr){
                arr = bigpicstr.split(",");
              }else{
                //默认图片
                arr = ["http://114.67.229.235/bigpic/flgm1.jpg","http://114.67.229.235/bigpic/flgm2.jpg","http://114.67.229.235/bigpic/flgm3.jpg"];
              }
              this_.productPics = arr;
            } else {
                this_.dataForm = {};
            }
        });
    },
    // 编辑
    submitForm: function() {
        this.$refs.dataForm.validate(valid => {
            if (valid) {
                this.$confirm("确认提交吗？", "提示", {}).then(() => {
                    let params = {};
                    // let params = Object.assign({}, this.dataForm);
                    params.pid = this.dataForm.id;
                    params.replycotent = this.dataForm.replycontent;
                    params.t = "feedback";
                    var this_ = this;
                    this.utils.request.editInfo(params, function(res) {
                        if (res.code == "0000") {
                            this_.$message({ message: "操作成功", type: "success" });

                            this_.$refs["dataForm"].resetFields();

                            this_.editDialogVisible = false;

                            this_.findPage(null);
                        } else {
                            this_.$message({
                                message: "操作失败, " + res.msg,
                                type: "error"
                            });
                        }
                    });
                });
            }
        });
    },
    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "系统参数下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
	  this.initColumns();
  }
};
</script>

<style scoped>
</style>
